package com.vincent.kdp.Activity;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.vincent.kdp.PostUrl;
import com.vincent.kdp.R;
import com.vincent.kdp.js.AddConsumeOperator;
import com.vincent.kdp.js.ReserveOperator;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/8/11 0011.
 */

public class ReserveActivity extends AppCompatActivity {

    @Bind(R.id.back_img)
    ImageView mBackImg;
    @Bind(R.id.toolbar_center_tv)
    TextView mToolbarCenterTv;
    @Bind(R.id.webView)
    WebView webView;

    private String barCode;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_addconsume);
        ButterKnife.bind(this);
        mToolbarCenterTv.setText("预订单");
        getParam(getIntent());
        this.initializeWebView();

    }

    private void getParam(Intent intent) {
        this.barCode = intent.getStringExtra("barCode");
    }

    @SuppressLint({"NewApi", "SetJavaScriptEnabled"})
    private void initializeWebView() {
        Log.d("AddConsumeActivity", barCode );

        webView.addJavascriptInterface(new ReserveOperator(ReserveActivity.this, barCode),
                "Consume");
        try {
            //String url = "file:///android_asset/LoginJs/login.html";
            String url = PostUrl.SERVICE_URL + "/H5/reserve/reserve.html";
            WebSettings webSettings = webView.getSettings();
            webSettings.setJavaScriptEnabled(true);
            webSettings.setAllowFileAccess(true);
            webSettings.setAllowFileAccessFromFileURLs(true);
            webSettings.setBuiltInZoomControls(false);
            webSettings.setSupportZoom(false);
            webSettings.setDisplayZoomControls(false);
            this.webView.loadUrl(url);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @OnClick({R.id.back_img})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_img:
                this. finish();
                overridePendingTransition(com.vincent.baseapp.R.anim.fragment_left_in, com.vincent.baseapp.R.anim.fragment_right_out);
                break;
        }
    }




}

